//
//  MainViewController.m
//  Tag-C
//
//  Created by KyuJin on 13. 2. 5..
//  Copyright (c) 2013년 monscape. All rights reserved.
//

#import "MainViewController.h"
#import "ManagementClass.h"
#import "GPSViewController.h"
#import "SearchTableViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

#pragma mark - View Life Cycle
- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Do any additional setup after loading the view from its nib.
}

- (void) viewDidAppear:(BOOL)animated
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    
    [self.view setAlpha:1.0f];
    
    [UIView commitAnimations];
}

- (void) viewWillAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNetworkNotification:) name:NetworkConnected object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNetworkNotification:) name:NetworkDisconnect object:nil];
    
    [self.view setAlpha:0.0f];
}

- (void) viewWillDisappear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
    if(m_audioBgm.isPlaying)
    {
        [m_audioBgm pause];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Event Listener
- (IBAction) buttonEventListener:(id)sender
{
    switch ([sender tag]) {
        case BUTTON_SEARCH:
        {
            TreeNode *resultArray = [[DaumMapParser getInstance] getTradeSearchResult:m_txtAddress.text];
            SearchTableViewController *resultView = [[SearchTableViewController alloc] initWithStyleTableData:UITableViewStylePlain resultArray:resultArray];
            UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:resultView];
            [resultView setTitle:m_txtAddress.text];
            [self presentModalViewController:navigation animated:YES];
        }
            break;
            
        case BUTTON_HOME:
            break;
            
        case BUTTON_SCHOOL:
            break;
            
        case BUTTON_COMPANY:
            break;
            
        case BUTTON_DRIVE:
            break;
            
        default:
            break;
    }
}

#pragma mark - Notification Receiver
- (void) receiveNetworkNotification:(NSNotification*)notifi
{
    if([notifi.name isEqual:NetworkConnected])
    {
        DebugLogDetailed(@"Network Connected");
    }
    else if([notifi.name isEqualToString:NetworkDisconnect])
    {
        DebugLogDetailed(@"Network Disconnected");
    }
    else
    {
        DebugLogDetailed(@"Unknown Notification");
    }
}

@end
